package com.lyf.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyf.mapper.UserMapper;
import com.lyf.pojo.User;
import com.lyf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(User user) {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.eq("name",user.getName());
        query.eq("password",user.getPassword());
        User userDB = userMapper.selectOne(query);

        if(userDB != null){
            return userDB;
        } else {
            throw new RuntimeException("认证失败");
        }
    }
}
